package com.ruoyi.charge.controller;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.charge.auth.entity.ApiToken;
import com.ruoyi.charge.auth.service.LoginTokenService;
import com.ruoyi.common.utils.ServletUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.charge.vo.CommissionRecordVo;
import com.ruoyi.charge.bo.CommissionRecordQueryBo;
import com.ruoyi.charge.bo.CommissionRecordAddBo;
import com.ruoyi.charge.bo.CommissionRecordEditBo;
import com.ruoyi.charge.service.ICommissionRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 分佣记录Controller
 *
 * @author fanqie
 * @date 2021-10-25
 */
@Api(value = "分佣记录控制器", tags = {"分佣记录管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/charge/commission_record")
public class CommissionRecordController extends BaseController {

    private final ICommissionRecordService iCommissionRecordService;
    private final LoginTokenService loginTokenService;

    /**
     * 查询分佣记录列表
     */
    @ApiOperation("查询分佣记录列表")
    @GetMapping("/list")
    public TableDataInfo<CommissionRecordVo> list(CommissionRecordQueryBo bo) {
        ApiToken apiToken = loginTokenService.getLoginInfo(ServletUtils.getRequest());
        if (apiToken.getType() == 0) {
            bo.setStoreId(apiToken.getUserId());
        } else {
            bo.setAgentId(apiToken.getUserId());
        }
        startPage();
        List<CommissionRecordVo> list = iCommissionRecordService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 获取分佣记录详细信息
     */
    @ApiOperation("获取分佣记录详细信息")
    @GetMapping("/{id}")
    public AjaxResult<CommissionRecordVo> getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(iCommissionRecordService.queryById(id));
    }


}
